package org.he.auth.controller;

import org.he.auth.dto.LoginDTO;
import org.he.auth.service.ILoginService;
import org.he.auth.vo.LoginVO;
import org.he.basic.data.ContextMap;
import org.he.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author He
 * @date 2023/12/5  11:43
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginServiceImpl;
    @PostMapping
    public AjaxResult login(@RequestBody LoginDTO loginDTO){
        try {
            LoginVO loginVO = loginServiceImpl.login(loginDTO);
            return AjaxResult.success(loginVO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("登录失败");
        }
    }

    @PutMapping
    public AjaxResult loginOut(){
        try {
            ContextMap.loginMap.clear();
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("退出失败");
        }
    }
}
